package com.ppc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ppc.context.BaseContext;
import com.ppc.entity.Complaint;
import com.ppc.mapper.worker.WorkerComplaintMapper;
import com.ppc.mapper.worker.WorkerMapper;
import com.ppc.result.PageResult;
import com.ppc.service.WorkerComplaintService;
import com.ppc.vo.ComplaintDetailVO;
import com.ppc.vo.ComplaintPageVO;
import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 工人举报接口
 *
 * @author Jeferry
 * @date 2023/12/20
 */
@Service
public class WorkerComplaintServiceImpl implements WorkerComplaintService {

  @Autowired
  private WorkerComplaintMapper ComplaintMapper;

  @Autowired
  private WorkerMapper workerMapper;

  /**
   * 创建举报
   *
   * @param requireId        举报的需求id
   * @param complaintType   举报类型
   */
  @Override
  public void createComplaint(Long requireId, String complaintType) {
    Complaint complaint = Complaint.builder()
        .requireId(requireId)
        .userId(BaseContext.getCurrentId())
        .complaintType(complaintType)
        .complaintStartTime(LocalDateTime.now())
        .complaintStatus(0)
        .build();
    ComplaintMapper.createComplaint(complaint);
  }

  /**
   * 查询举报列表
   *
   * @param page           页码
   * @param pageSize       页大小
   * @param complaintStatus 举报状态
   * @return {@link PageResult}
   */
  @Override
  public PageResult queryComplaintList(Integer page, Integer pageSize, Integer complaintStatus) {
    //只查询跟自己有关的
    Long userId = BaseContext.getCurrentId();
    PageHelper.startPage(page, pageSize);
    Page<ComplaintPageVO> p = ComplaintMapper.pageQuery(complaintStatus,userId);
    return new PageResult(p.getTotal(), p.getResult());
  }

  /**
   * 查询举报详情
   *
   * @param complaintId 举报id
   * @return {@link ComplaintDetailVO}
   */
  @Override
  public ComplaintDetailVO queryComplaintDetail(Long complaintId) {
    ComplaintDetailVO complaint = ComplaintMapper.queryComplaintDetail(complaintId);
    return complaint;
  }
}
